package org.apache.jsp.view.cliente;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import br.com.skpharma.vo.*;
import br.com.skpharma.dao.*;
import java.util.*;
import java.text.SimpleDateFormat;

public final class inserir_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();

  private static java.util.List _jspx_dependants;

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.AnnotationProcessor _jsp_annotationprocessor;

  public Object getDependants() {
    return _jspx_dependants;
  }

  public void _jspInit() {
    _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
    _jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName());
  }

  public void _jspDestroy() {
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      response.setContentType("text/html; charset=ISO-8859-1");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\r\n");
      out.write("\r\n");

	

	if(request.getParameter("Salvar") != null){
	DAOCliente daoCliente = new DAOCliente();
	daoCliente.getClienteVO().setLogin(request.getParameter("login"));
	daoCliente.getClienteVO().setSenha(request.getParameter("senha"));
	daoCliente.getClienteVO().setNome(request.getParameter("nome"));
	SimpleDateFormat formataData = new SimpleDateFormat("dd/MM/yyyy");
	daoCliente.getClienteVO().setDataNasc(formataData.parse(request.getParameter("dataNascimento")));
	daoCliente.getClienteVO().setCpf(request.getParameter("cpf"));
	daoCliente.getClienteVO().setTelefone(request.getParameter("telefone"));
	daoCliente.getClienteVO().setCelular(request.getParameter("celular"));
	daoCliente.getClienteVO().setEmail(request.getParameter("email"));
	daoCliente.getClienteVO().getEnderecoVO().setRua(request.getParameter("rua"));
	daoCliente.getClienteVO().getEnderecoVO().setNumero(Integer.parseInt(request.getParameter("numero")));
	daoCliente.getClienteVO().getEnderecoVO().setBairro(request.getParameter("bairro"));
	daoCliente.getClienteVO().getEnderecoVO().setCep(request.getParameter("cep"));
	
	PerfilVO perfil = new PerfilVO();
	DAOPerfil daoPerfil = new DAOPerfil();
	daoPerfil.carregar(1);
	perfil = daoPerfil.getPerfilVO();
	daoCliente.getClienteVO().setPerfilVO(perfil);
		
    CidadeVO cidade = new CidadeVO();
	cidade.setCod(Integer.parseInt(request.getParameter("cidade")));
	daoCliente.getClienteVO().getEnderecoVO().setCidadeVO(cidade);
	daoCliente.salvar();

      out.write("\r\n");
      out.write("\r\n");
      out.write("\t");
 if (session.getAttribute("admLogado") != null){ 
      out.write("\r\n");
      out.write("\t\t");
      if (true) {
        _jspx_page_context.forward("index.jsp");
        return;
      }
      out.write('\r');
      out.write('\n');
      out.write('	');
} else { 
      out.write("\r\n");
      out.write("\t\t<script language=\"javascript\">\r\n");
      out.write("\t\t\twindow.close();\r\n");
      out.write("\t\t\t\r\n");
      out.write("\r\n");
      out.write("\t\t\t\t\r\n");
      out.write("\t\t</script>\r\n");
      out.write("\t");
} 
      out.write("\r\n");
      out.write("\t\r\n");

}

      out.write("\r\n");
      out.write("\r\n");
      out.write("<html>\r\n");
      out.write("\r\n");
      out.write("<head>\r\n");
      out.write("<title></title>\r\n");
      out.write("<link href=\"../css/css.css\" rel=\"stylesheet\" type=\"text/css\">\r\n");
      out.write("<style type=\"text/css\">\r\n");
      out.write("<!--\r\n");
      out.write(".style3 {color: #FFFFFF; font-weight: bold; }\r\n");
      out.write("-->\r\n");
      out.write("</style>\r\n");
      out.write("</head>\r\n");
      out.write("\r\n");
      out.write("<body>\r\n");
      out.write("\r\n");
      out.write("<p align=\"center\">Cadastro</p>\r\n");
      out.write("\r\n");
      out.write("<blockquote>\r\n");
      out.write("  <form method=\"POST\" name=\"formcliente\" action=\"inserir.jsp\" onSubmit=\"validarForm()\">\r\n");
      out.write("    <div align=\"center\">\r\n");
      out.write("      <table border=\"0\" cellpadding=\"5\" cellspacing=\"2\" style=\"font-size:12px\">\r\n");
      out.write("        <tr>\r\n");
      out.write("          <td width=\"50%\" height=\"23\" bgcolor=\"#941C1D\"><span class=\"style3\">Login:</span></td>\r\n");
      out.write("        <td width=\"50%\" height=\"23\" bgcolor=\"#f2f2f2\"><input style=\"font-size:12px\" type=\"text\" id=\"login\" name=\"login\" size=\"40\"></td>\r\n");
      out.write("      </tr>\r\n");
      out.write("        <tr>\r\n");
      out.write("          <td width=\"50%\" height=\"23\" bgcolor=\"#941C1D\"><span class=\"style3\">Senha:</span></td>\r\n");
      out.write("        <td width=\"50%\" height=\"23\" bgcolor=\"#f2f2f2\"><input style=\"font-size:12px\" type=\"text\" name=\"senha\" size=\"40\"></td>\r\n");
      out.write("      </tr>\r\n");
      out.write("        <tr>\r\n");
      out.write("          <td width=\"50%\" height=\"23\" bgcolor=\"#941C1D\"><span class=\"style3\">Nome:</span></td>\r\n");
      out.write("        <td width=\"50%\" height=\"23\" bgcolor=\"#f2f2f2\"><input style=\"font-size:12px\" type=\"text\" name=\"nome\" size=\"40\"></td>\r\n");
      out.write("      </tr>\r\n");
      out.write("        <tr>\r\n");
      out.write("          <td width=\"50%\" height=\"23\" bgcolor=\"#941C1D\"><span class=\"style3\">Data Nascimento:</span></td>\r\n");
      out.write("        <td width=\"50%\" height=\"23\" bgcolor=\"#f2f2f2\"><input style=\"font-size:12px\" type=\"text\" name=\"dataNascimento\" size=\"20\"></td>\r\n");
      out.write("      </tr>\r\n");
      out.write("        <tr>\r\n");
      out.write("          <td width=\"50%\" height=\"23\" bgcolor=\"#941C1D\"><span class=\"style3\">CPF:</span></td>\r\n");
      out.write("        <td width=\"50%\" height=\"23\" bgcolor=\"#f2f2f2\"><input style=\"font-size:12px\" type=\"text\" name=\"cpf\" size=\"20\"></td>\r\n");
      out.write("      </tr>\r\n");
      out.write("        <tr>\r\n");
      out.write("          <td width=\"50%\" height=\"23\" bgcolor=\"#941C1D\"><span class=\"style3\">Telefone:</span></td>\r\n");
      out.write("        <td width=\"50%\" height=\"23\" bgcolor=\"#f2f2f2\"><input style=\"font-size:12px\" type=\"text\" name=\"telefone\" size=\"20\"></td>\r\n");
      out.write("      </tr>\r\n");
      out.write("        <tr>\r\n");
      out.write("          <td width=\"50%\" height=\"23\" bgcolor=\"#941C1D\"><span class=\"style3\">Celular:</span></td>\r\n");
      out.write("        <td width=\"50%\" height=\"23\" bgcolor=\"#f2f2f2\"><input style=\"font-size:12px\" type=\"text\" name=\"celular\" size=\"20\"></td>\r\n");
      out.write("      </tr>\r\n");
      out.write("        <tr>\r\n");
      out.write("          <td width=\"50%\" height=\"23\" bgcolor=\"#941C1D\"><span class=\"style3\">E-mail:</span></td>\r\n");
      out.write("        <td width=\"50%\" height=\"23\" bgcolor=\"#f2f2f2\"><input style=\"font-size:12px\" type=\"text\" name=\"email\" size=\"40\"></td>\r\n");
      out.write("      </tr>\r\n");
      out.write("        <tr>\r\n");
      out.write("          <td width=\"50%\" height=\"23\" bgcolor=\"#941C1D\"><span class=\"style3\">Rua:</span></td>\r\n");
      out.write("        <td width=\"50%\" height=\"23\" bgcolor=\"#f2f2f2\"><input style=\"font-size:12px\" type=\"text\" name=\"rua\" size=\"40\"></td>\r\n");
      out.write("      </tr>\r\n");
      out.write("        <tr>\r\n");
      out.write("          <td width=\"50%\" height=\"23\" bgcolor=\"#941C1D\"><span class=\"style3\">Número:</span></td>\r\n");
      out.write("        <td width=\"50%\" height=\"23\" bgcolor=\"#f2f2f2\"><input style=\"font-size:12px\" type=\"text\" name=\"numero\" size=\"10\"></td>\r\n");
      out.write("      </tr>\r\n");
      out.write("        <tr>\r\n");
      out.write("          <td width=\"50%\" height=\"23\" bgcolor=\"#941C1D\"><span class=\"style3\">Bairro:</span></td>\r\n");
      out.write("        <td width=\"50%\" height=\"23\" bgcolor=\"#f2f2f2\"><input style=\"font-size:12px\" type=\"text\" name=\"bairro\" size=\"40\"></td>\r\n");
      out.write("      </tr>\r\n");
      out.write("        <tr>\r\n");
      out.write("          <td width=\"50%\" height=\"23\" bgcolor=\"#941C1D\"><span class=\"style3\">CEP:</span></td>\r\n");
      out.write("        <td width=\"50%\" height=\"23\" bgcolor=\"#f2f2f2\"><input style=\"font-size:12px\" type=\"text\" name=\"cep\" size=\"20\"></td>\r\n");
      out.write("      </tr>\r\n");
      out.write("        <tr>\r\n");
      out.write("          <td width=\"50%\" height=\"19\" bgcolor=\"#941C1D\"><span class=\"style3\">Cidade:</span></td>\r\n");
      out.write("        <td width=\"50%\" height=\"19\" bgcolor=\"#f2f2f2\"><select style=\"font-size:12px\" name=\"cidade\">\r\n");
      out.write("          ");

      		DAOCidade daoCidade = new DAOCidade();
      		ArrayList lista = new ArrayList();
      		lista = daoCidade.obterLista();		
      		for (int i = 0; i<lista.size(); i++){
      
      out.write("\r\n");
      out.write("          <option value=\"");
      out.print(((CidadeVO)lista.get(i)).getCod());
      out.write('"');
      out.write('>');
      out.print(((CidadeVO)lista.get(i)).getDs());
      out.write("</option>\r\n");
      out.write("          ");

        }
	  
      out.write("      \r\n");
      out.write("          </select>      </td>\r\n");
      out.write("      </tr>\r\n");
      out.write("        <tr>\r\n");
      out.write("          <td width=\"100%\" height=\"19\" colspan=\"2\"><div align=\"center\">\r\n");
      out.write("            \r\n");
      out.write("            <div align=\"center\">\r\n");
      out.write("              <input type=\"submit\" value=\"Salvar\" name=\"Salvar\" style=\"font:Verdana, Arial, Helvetica, sans-serif; font-size:12px\">\r\n");
      out.write("              <input type=\"reset\" value=\"Limpar\" name=\"Limpar\" style=\"font:Verdana, Arial, Helvetica, sans-serif; font-size:12px\">\t\r\n");
      out.write("          </div></td>\r\n");
      out.write("      </tr>\r\n");
      out.write("      </table>\r\n");
      out.write("  </div>\r\n");
      out.write("  </form>\r\n");
      out.write("</blockquote>\r\n");
      out.write("</body>\r\n");
      out.write("</html>\r\n");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try { out.clearBuffer(); } catch (java.io.IOException e) {}
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
